package logic

import (
	"context"
	"strconv"
	"taobao/models/mysql"

	"taobao/internal/svc"
	"taobao/taobao"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowGoodsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowGoodsLogic {
	return &ShowGoodsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowGoodsLogic) ShowGoods(in *taobao.ShowRequest) (*taobao.ShowResponse, error) {
	// todo: add your logic here and delete this line
	var show mysql.Goods
	mysql.DB.Debug().Where("id =?", in.GoodsId).Find(&show)
	return &taobao.ShowResponse{
		UserId:     int64(show.UserId),
		GoodsTitle: show.GoodsTitle,
		GoodsPrice: float32(show.GoodsPrice),
		Stock:      int64(show.Stock),
		GoodsCover: show.GoodsCover,
		Status:     strconv.Itoa(show.Status),
		CheckStaus: int64(show.CheckStaus),
		GoodsId:    int64(show.ID),
	}, nil
}
